package com.hu.zhcc.shiro.controller.Appointment;

import com.hu.zhcc.shiro.entity.Appointment.Entry;
import com.hu.zhcc.shiro.entity.Appointment.Entryteam;
import com.hu.zhcc.shiro.entity.Appointment.TSetmeal;
import com.hu.zhcc.shiro.service.Appointment.EntryService;
import com.hu.zhcc.shiro.service.Appointment.EntryteamService;
import com.hu.zhcc.shiro.service.Appointment.TSetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/****
 * 项目组Controller
 */
@RestController
public class EntryteamController {

    @Autowired
    private EntryteamService entryteamService;

    @Autowired
    private TSetmealService tSetmealService;

    /****
     * 项目组连接项目查询
     * @param name
     * @return
     */
    @PostMapping("muchEntry")
    private List<Entry> muchEntryteam(String name) {
        Map map = new HashMap();
        map.put("name", name);
        List<Entryteam> entryteamList = entryteamService.connectSelectEntry(map);
        List<Entry> list = new ArrayList();
        for (Entryteam entryteam : entryteamList) {
            for (Entry entry : entryteam.getEntryList()) {
                list.add(entry);
            }
        }
        return list;
    }

    /****
     * 套餐连接项目组查询
     * @param name
     * @return
     */
    @PostMapping("muchEntryteam")
    private List<Entryteam> muchEntry(String name) {
        Map map = new HashMap();
        map.put("name", name);
        List<TSetmeal> tSetmeals = tSetmealService.connectionEntryTeam(map);
        ArrayList<Entryteam> list = new ArrayList();
        for (TSetmeal tSetmeal : tSetmeals) {
            for (Entryteam entryteam : tSetmeal.getEntryteamList()) {
                list.add(entryteam);
            }
        }
        return list;
    }

    /****
     * 项目组删除
     * @param id
     * @return
     */
    @DeleteMapping("deletTeam{id}")
    private int deletTeam(@PathVariable("id") int id) {
        return tSetmealService.deleteTeam(id);
    }

    /****
     * 查询套餐
     * @return
     */
    @PostMapping("selectSetMeals")
    private List<TSetmeal> selectSetMeals() {
        return tSetmealService.selectAllMeal();
    }

    /****
     * 项目组添加
     * @param entryteam
     * @return
     */
    @PostMapping("addEntryteamByT")
    private int addEntryteamByT(@RequestBody Entryteam entryteam) {
        return entryteamService.insertSelective(entryteam);
    }
}
